//
//  ViewController.m
//  VideoRender
//
//  Created by 南风 on 2023/10/9.
//

#import "ViewController.h"
#import "KFVideoCaptureViewController.h"
#import "KFVideoOpenGLRenderViewController.h"
#import "KFVideoMetalRenderViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//    button.backgroundColor = [UIColor redColor];
//    button.frame = CGRectMake(100, 100, 50, 50);
//    [self.view addSubview:button];
//    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    
    [self prepareUI];
}

- (UIButton *)createButtonWithTitle:(NSString *)title selector:(SEL __nullable)selector {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:title forState:UIControlStateNormal];
    button.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0f green:arc4random()%256/255.0f blue:arc4random()%256/255.0f alpha:1];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    if(selector) {
        [button addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
    }
    return button;
}


- (void)prepareUI {
    NSArray *titleList = @[@"系统layer渲染",@"OpenGL渲染",@"Metal渲染"];
    UIButton *lastButton = nil;
    for (int i = 0; i < titleList.count; i++) {
        NSString *action = [NSString stringWithFormat:@"action%d",i+1];
        UIButton *button = [self createButtonWithTitle:titleList[i] selector:NSSelectorFromString(action)];
        if(lastButton) {
            button.frame = CGRectMake(0, CGRectGetMaxY(lastButton.frame) + 10, CGRectGetWidth(self.view.frame), 44);
        }else {
            button.frame = CGRectMake(0, 150, CGRectGetWidth(self.view.frame), 44);
        }
        [self.view addSubview:button];
        lastButton = button;
    }
    
}

- (void)action1 {
    KFVideoCaptureViewController *vc = [[KFVideoCaptureViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)action2 {
    KFVideoOpenGLRenderViewController *vc = [[KFVideoOpenGLRenderViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)action3 {
    KFVideoMetalRenderViewController *vc = [[KFVideoMetalRenderViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
